package com.hotec.PROJECT_NAME.modules.sys.controller;

import com.hotec.PROJECT_NAME.modules.sys.entity.SysRoleAccount;
import com.hotec.PROJECT_NAME.modules.sys.service.SysRoleAccountService;
import com.hotec.PROJECT_NAME.component.basic.BaseController;
import com.hotec.PROJECT_NAME.component.basic.ConstantKey;
import com.hotec.PROJECT_NAME.component.basic.JsonContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author llb

 */
@RestController
@RequestMapping("sys/roleAccount")
public class SysRoleAccountController extends BaseController {

    @Autowired
    SysRoleAccountService service;
    /**
     * 根据主键查询对象
     * @param id
     * @return
     */
    @GetMapping("get")
    public JsonContent get(String id) {
        return this.success(service.get(id));
    }

    /**
     * 分页查询列表
     * @param entity
     * @param pageNum
     * @param pageSize
     * @return
     */
    @PostMapping("query")
    public JsonContent query(@RequestParam(required = false, value = "pageNum", defaultValue = ConstantKey.DEFAULT_PAGE_NUM) Integer pageNum,
                            @RequestParam(required = false, value = "pageSize", defaultValue = ConstantKey.DEFAULT_PAGE_SIZE) Integer pageSize,
                            @RequestBody SysRoleAccount entity) {
        return this.success(service.query(pageNum, pageSize, ConstantKey.DEFAULT_ORDER_BY, entity));
    }

    /**
     * 根据对象列表逻辑删除
     * @param entityList
     * @return
     */
    @PostMapping("delete")
    public JsonContent delete(@RequestBody List<SysRoleAccount> entityList) {
        service.deleteById(entityList);
        return this.success().setMessage("删除成功！");
    }

    /**
     * 保存更新
     * @return
     */
    @PostMapping("save")
    public JsonContent save(@Valid @RequestBody SysRoleAccount entity) {
        service.save(entity);
        return this.success().setMessage("操作成功！");
    }


    /**
     * 根据对象条件，查询单条数据
     *
     * @return
     */
    @PostMapping("getOne")
    public JsonContent getOne(@RequestBody SysRoleAccount entity) {
        return this.success(service.getOne(entity));
    }
}
